/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qp.smsmarketing.utils.report;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.qp.smsmarketing.dao.MensagemDAO;
import com.qp.smsmarketing.entity.MensagemContato;
import java.io.FileOutputStream;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.List;

/**
 *
 * @author joasramos
 */
public class ReportEstatistica {

    /**
     * The resulting PDF file.
     */
    public static final String RESULT = "../teste.pdf";
    private Paragraph titulo;
    private Chapter ch;
    private Section sc;
    private PdfPTable pTable;
//    private PdfPCell celula1, celula2, celula3;
    private Date date1, date2;

    public ReportEstatistica(Date data1, Date data2) {
        this.date1 = data1;
        this.date2 = data2;
    }

    public void criarPDF(String file) {

        Document document = new Document();
        try {
            PdfWriter.getInstance(document, new FileOutputStream(file));
            document.open();
            titulo = new Paragraph("Estatisticas periódicas\n\n",
                    FontFactory.getFont(FontFactory.COURIER_OBLIQUE,
                    14, Font.BOLD, new BaseColor(105, 105, 105)));
            ch = new Chapter(titulo, 0);
            ch.setNumberDepth(0);
            sc = ch.addSection(titulo);
            pTable = new PdfPTable(2);
            pTable.addCell(new Paragraph("Total de Mensagens Enviadas"));
            String total = String.valueOf(getList().size());
            pTable.addCell(total);
            document.add(sc);
            document.add(pTable);

        } catch (Exception ex) {
            Logger.getLogger(ReportEstatistica.class.getName()).
                    log(Level.SEVERE, "Erro de Instancia PdfWriter!", ex);
        }
        document.close();

    }

    /*
     * @return
     */
    public List<MensagemContato> getList() {
        List<MensagemContato> list = new MensagemDAO().getPdfList(this.date1, this.date2);
        return list;
    }
}
